// #ifdef MP-WEIXIN
/**
 * 获取用户code
 * @return {Promise.resolve(string|false)}
 */
export function getCode () {
	return new Promise(resolve => {
		wx.login({
			success: (res) => {
				if (res.code) {
					return resolve(res.code)
				} else {
					return resolve(false)
				}
			},
			fail: () => {
				return resolve(false)
			}
		})
	})
}

// export async function getUserInfo () {
// 	return new Promise(resolve => {
// 		wx.getUserInfo({
// 			success: (res) => {
// 				console.log(res)
// 				return resolve(res.userInfo)
// 			},
// 			fail: () => {
// 				return resolve(false)
// 			}
// 		})
// 	})
// }


/**
 * 获取授权状态
 */
export function getAuthStatus () {
	return new Promise(resolve => {
		wx.getSetting({
		    success(res) {
				return resolve(res.authSetting)
			},
			fail() {
				// 获取授权状态失败
				return resolve(false)
			}
		})
	})
}

// 开启指定授权，用户拒绝后无法重新打开弹窗，只有通过让用户点击按钮去主动打开
export function openAuth (scope) {
	return new Promise(resolve => {
	    wx.authorize({
			scope: scope,
			success (res) {
				return resolve(true)
			},
			fail (err) {
				return resolve(false)
			}
		})
	})
}

// 打开设置页面
export async function openSetting () {
	// 获取用户位置（进入小程序和离开小程序时都获取）
	wx.openSetting({
		// 设置权限后执行
		success (res) {
		    console.log(res.authSetting)
		},
		fail (err) {
			console.log(err)
		}
	})
}

// #endif

/**
 * 获取当前位置经纬度
 * @return {Promise.resolve(Object | false)}
 */
export function getLocation () {
	return new Promise(resolve => {
		uni.getLocation({
		    type: 'gcj02',
		    success: (res) => {
				return resolve(res)
		    },
			fail (err) {
				return resolve(false)
			}
		})
	})
}
export function ToastOk(msg) {
	return new Promise(resolve => {
		uni.showToast({
			title: msg,
			icon: 'success',
			duration: 3000
		})
	})
}
export function ToastFail(msg) {
	return new Promise(resolve => {
		uni.showToast({
			title: msg,
			icon: 'none',
			duration: 3000
		})
	})
}
/**
 * 打开地图选择位置
 * @return {Promise.resolve(Object | false)}
 */
export function openMapToChooseLocation () {
	
}
